<?
include('inc/addondb.php');

if(isset($_GET['id'])){
if($_GET['step'] == "skip"){
mysql_query("INSERT INTO `daily` (user_id, site_id) VALUES('{$_GET['usr']}', '{$_GET['id']}')");
mysql_query("UPDATE `users` SET `coins`=`coins`+'100' WHERE `id`='{$_GET['usr']}'");
mysql_query("UPDATE `dailyb` SET `earned`=`earned`+'1' WHERE `site_id`='{$_GET['id']}'");
echo "<table cellpadding=\"2\" cellspacing=\"0\" width=\"500\" align=\"center\" class=\"mainfocus\"><tr><td align=\"center\"><font size=\"3\"><b>Bonus Claimed!</b></font></td></tr></table>";
}else{
$dbres1				= mysql_query("SELECT * FROM `twitter` WHERE `user`='{$protect['usr']}'");
$data3 = mysql_fetch_object($dbres1);
$site = mysql_fetch_object(mysql_query("SELECT * FROM `twitter` WHERE `id`='{$protect['id']}'"));
 $url  = "http://api.twitter.com/1/friendships/exists.json?screen_name_a=" . $data3->t_name . "&screen_name_b=".$site->t_name;
 $page = get_data($url);
 $json_a = json_decode($page,true);
$plused1 = mysql_query("SELECT * FROM `followed` WHERE `site_id`='{$protect['id']}' AND `user_id`='{$protect['usr']}'");
$plused  = mysql_num_rows($plused1);
$tw1 = mysql_query("SELECT * FROM `twitter` WHERE `id`='{$protect['id']}' AND `active`='0'");
$tw = mysql_fetch_object($tw1);
$tw22 = mysql_query("SELECT * FROM `twitter` WHERE `id`='{$protect['id']}'");
$tw2 = mysql_fetch_object($tw22);
if ($page == FALSE) { 
 echo "<table cellpadding=\"2\" cellspacing=\"0\" width=\"500\" align=\"center\" class=\"mainfocus\"><tr><td align=\"center\"><font size=\"3\"><b>Error!</b></font></td></tr><tr><td><center><b>We can't verify followers!</b></center></td></tr></table>";
}else if($plused > 0){
echo "<table cellpadding=\"2\" cellspacing=\"0\" width=\"500\" align=\"center\" class=\"mainfocus\"><tr><td align=\"center\"><font size=\"3\"><b>Error!</b></font></td></tr><tr><td><center><b>You already followed @".$site->t_name."!</b></center></td></tr></table>";
}else if (strpos($page, "true") !== FALSE) {
mysql_query("UPDATE `users` SET `coins`=`coins`+'$tw->cpc' WHERE `id`='{$protect['usr']}'");
mysql_query("UPDATE `users` SET `coins`=`coins`-'$tw->cpc' WHERE `id`='$tw2->user'");
mysql_query("UPDATE `twitter` SET `earned`=`earned`+'1' WHERE `user`='$tw2->user'");
mysql_query("INSERT INTO `followed` (user_id, site_id) VALUES('{$protect['usr']}', '{$protect['id']}')");
$aff1 = mysql_query("SELECT ref FROM `users` WHERE `login`='{$data->login}'");
$aff = mysql_fetch_object($aff1);
if($aff->ref > 0){
$coins = $tw->cpc * $referralPercent;
mysql_query("UPDATE `users` SET `coins`=`coins`+'$coins' WHERE `id`='{$aff->ref}'");
}
echo "<table cellpadding=\"2\" cellspacing=\"0\" width=\"500\" align=\"center\" class=\"mainfocus\"><tr><td align=\"center\"><font size=\"3\"><b>Success!</b></font></td></tr><tr><td><center><b>You followed @".$site->t_name."!<br><font color=\"#d4a1ff\" size=\"3\">You got ".$tw->cpc." Coins!</font></center></td></tr></table>";
}else{
echo "<table cellpadding=\"2\" cellspacing=\"0\" width=\"500\" align=\"center\" class=\"maintable\"><tr><td><center><b>Twitter says you aren't following @".$site->t_name."!</b><br><i>Check again if you are logged into " . $data3->t_name . " on Twitter.</i><br><b>Try Confirming again or Skip them!</b></center></td></tr></table><br>";
}
}}
?>